import { createRouter, createWebHashHistory } from "vue-router";

const routers = [
  {
    path: '/',
    redirect:'/home'
  },
  {
    path: '/home',
    component: () => import('../views/Home/Home.vue'),
    meta: {
      isShowNav:true
    }
  },
  {
    path: '/user',
    component: () => import('../views/User/User.vue'),
    meta: {
      isShowNav:true
    }
  },
  {
    path: '/login',
    component: () => import('../views/Login/Login.vue'),
    meta: {
      isShowNav:false
    }
  },
  {
    path: '/category',
    component: () => import('../views/Category/Category.vue'),
    meta: {
      isShowNav:true
    }
  },
  {
    path: '/cart',
    component: () => import('../views/Cart/Cart.vue'),
    meta: {
      isShowNav:true
    }
  },
  {
    path: '/info/:productId',
    component: () => import('../views/Info/Info.vue'),
    meta: {
      isShowNav:false
    }
  },
  {
    path: '/addressList',
    component: () => import('../views/Address/AddressList.vue'),
    meta: {
      isShowNav:false
    }
  },
  {
    path: '/addressEdit',
    component: () => import('../views/Address/AddressAddAndEdit.vue'),
    meta: {
      isShowNav:false
    }
  },
  {
    path: '/createOrder',
    component: () => import('../views/CreateOrder/CreateOrder.vue'),
    meta: {
      isShowNav:false
    }
  },
  {
    path: '/order',
    component: () => import('../views/Order/Order.vue'),
    meta: {
      isShowNav: false,
      til: "订单页"
    }
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    ...routers,
    {path:"/:pathMatch(.*)",redirect:"/"}
  ]
})

router.beforeEach((to,from) => {
  document.title  = to.meta.til || "皮皮商城-正品低价、品质保障、配送及时、轻松购物"
})
export default router;